package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectComplaintListListener;
import com.longxi.tianjintianbao.model.complaint.Complaint;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class ComplaintListViewBinder extends ItemViewBinder<Complaint, ComplaintListViewBinder.ViewHolder> {

    SelectComplaintListListener listener;

    public ComplaintListViewBinder(SelectComplaintListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_task_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Complaint complaint) {
        holder.mTvDate.setText(complaint.getComplaintdate());
        holder.mTvStatus.setText(complaint.getPerson() + " " + complaint.getState());
        holder.mTvName.setText("业主—" + complaint.getName());
        holder.mTvAddress.setText(complaint.getAddress().replace("/", "-"));
        holder.mTvTaskContent.setText("单据类别: " + complaint.getBilltype() + "\n单据内容: " + complaint.getContent());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(complaint);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvDate;
        TextView mTvStatus;
        TextView mTvName;
        TextView mTvAddress;
        TextView mTvTaskContent;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
            mTvName = itemView.findViewById(R.id.tvName);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvTaskContent = itemView.findViewById(R.id.tvTaskContent);
        }
    }
}
